package core.util
{
	import core.RekooEvent;
	import core.RekooEventType;
	
	import mx.controls.Alert;
	import mx.modules.ModuleLoader;
	
	public class MenuBuilder
	{
		private static var _instance:MenuBuilder;
		private var _main:ModuleLoader;
		private var _clazz:String = "";
		private var _index:int = 0;
		public function MenuBuilder(lock:singoton)
		{
			if (lock == null) {
                throw new Error( "You Can Only Have One MenuBuilder" );
            }
		}
		
		public function get clazz():String
		{
			return _clazz;
		}
		
		//以下定义的id必须是对应的module的包名
		private var menuSource:Array = [
        	{"id":"library","data":[
        				{"label":"一览",			"event":RekooEventType.MENU_LIB_VIEW},
        				{"label":"还书",			"event":RekooEventType.MENU_LIB_RESTORE},
        				{"label":"新书推荐",		"event":RekooEventType.MENU_LIB_NEW}
        			]},
        	{"id":"seat","data":[
        				{"label":"一览",			"event":RekooEventType.MENU_SEAT_VIEW},
        				{"label":"换座位",		"event":RekooEventType.MENU_SEAT_CHANGE}
        			]},
        	{"id":"order","data":[
        				{"label":"餐厅订餐一览",	"event":RekooEventType.MENU_ORDER_VIEW_REST},
        				{"label":"员工订餐一览",	"event":RekooEventType.MENU_ORDER_VIEW_STUF},
        				{"label":"订餐",			"event":RekooEventType.MENU_ORDER_NEW},
        				{"label":"管理",			"event":RekooEventType.MENU_ORDER_CONFIG}
        			]},
        	{"id":"tool","data":[
        				{"label":"工具1",		"event":RekooEventType.MENU_TOOL_1},
        				{"label":"工具2",		"event":RekooEventType.MENU_TOOL_2}
        			]},
        	{"id":"config","data":[
        				{"label":"修改资料",		"event":RekooEventType.MENU_CONFIG_MODIFY},
        				{"label":"人员管理",		"event":RekooEventType.MENU_CONFIG_USER},
        				{"label":"系统设置",		"event":RekooEventType.MENU_CONFIG_SYSTEM}
        			]},
        	{"id":"help","data":[
        				{"label":"系统帮助",		"event":RekooEventType.MENU_HELP}
        			]}
        ];
		
		public function buildMenu(index:int):Array
		{
			_index = index;
			_clazz = menuSource[index]["id"];
			return menuSource[index]["data"];
		}
		
		public static function getInstance():MenuBuilder
		{
			if(_instance == null)
			{
				_instance = new MenuBuilder(new singoton);
			}
			return _instance;
		}
		
		public function getModuleUrl(e:RekooEvent = null):String
		{
			var sub:String = "";
			if(e == null)
			{
				sub = menuSource[_index]["data"][0]["event"];
			}
			else
			{
				sub = String(e.data);
			}
			return "module/"+_clazz+"/"+sub+".swf";
		}
		
		public function menuClick(event:RekooEvent):void
		{
			trace("menuClick");
		}
	}
}
class singoton{}